###-*- R -*- Unix Specific ----

.Library <- file.path(R.home(), "library")
.Library.site <- Sys.getenv("R_LIBS_SITE")
.Library.site <- if(!nchar(.Library.site)) file.path(R.home(), "site-library") else unlist(strsplit(.Library.site, ":"))
.Library.site <- .Library.site[file.exists(.Library.site)]

invisible(.libPaths(c(unlist(strsplit(Sys.getenv("R_LIBS"), ":")),
                      unlist(strsplit(Sys.getenv("R_LIBS_USER"), ":")
                      ))))

local({
## we distinguish between R_PAPERSIZE as set by the user and by configure
papersize <- Sys.getenv("R_PAPERSIZE_USER")
if(!nchar(papersize)) {
    lcpaper <- Sys.getlocale("LC_PAPER") # might be null: OK as nchar is 0
    papersize <- if(nchar(lcpaper))
        if(length(grep("(_US|_CA)", lcpaper))) "letter" else "a4"
    else Sys.getenv("R_PAPERSIZE")
}
options(papersize = as.vector(papersize),
        printcmd = as.vector(Sys.getenv("R_PRINTCMD")),
        latexcmd = as.vector(Sys.getenv("R_LATEXCMD")),
        dvipscmd = as.vector(Sys.getenv("R_DVIPSCMD")),
        texi2dvi = as.vector(Sys.getenv("R_TEXI2DVICMD")),
        browser = as.vector(Sys.getenv("R_BROWSER")),
        pager = file.path(R.home(), "bin", "pager"),
        pdfviewer = as.vector(Sys.getenv("R_PDFVIEWER")),
        useFancyQuotes = TRUE)
})

## non standard settings for the R.app GUI of the Mac OS X port
if(.Platform$GUI == "AQUA") {
    ## this is set to let RAqua use both X11 device and
    ## X11/TclTk
    if (Sys.getenv("DISPLAY") == "")
	Sys.setenv("DISPLAY" = ":0")

    ## this is to allow g77 compiler to work
    Sys.setenv("PATH" = paste(Sys.getenv("PATH"),":/usr/local/bin",sep = ""))
}## end "Aqua"

local({
    tests_startup <- Sys.getenv("R_TESTS")
    if(nzchar(tests_startup)) source(tests_startup)
})
